package com.kfm.pm.manage;

public class StudentManagement implements StudentManage, StudentManage2 {


    @Override
    public void test() {

    }

    static void test01() {}

    @Override
    public void printInfo(Student[] students) {
        for (Student student : students) {
            System.out.println(student);
        }
    }

    @Override
    public void printAvgScore(Student[] students) {
        double sum = 0;
        for (Student student : students) {
            sum += student.getScore();
        }
        System.out.println(sum / students.length);
    }

    @Override
    public void printInfo2(Student[] students) {
        for (Student student : students) {
            System.out.println(student);
        }
        int maleCount = 0;
        int femaleCount = 0;
        for (Student student : students) {
            if (student.getGender() == '男') {
                maleCount ++;
            } else if (student.getGender() == '女') {
                femaleCount ++;
            }
        }
        System.out.printf("男生人数：%d, 女生人数%d", maleCount, femaleCount);
        System.out.println();
    }

    @Override
    public void printAvgScore2(Student[] students) {
        for (int i = 0; i < students.length - 1; i++) {
            for (int j = 0; j < students.length - i - 1; j++) {
                if (students[j].getScore() > students[j + 1].getScore()) {
                    Student stu = students[j];
                    students[j] = students[j + 1];
                    students[j + 1] = stu;
                }
            }
        }
        double sum = 0;
        for (int i = 1; i < students.length - 1; i++) {
            sum += students[i].getScore();
        }
        System.out.println(sum / (students.length - 2));
    }
}


class Test {

    public static void main(String[] args) {
        Student stu1 = new Student("张三", '男', 90);
        Student stu2 = new Student("李四", '男', 81);
        Student stu3 = new Student("王五", '女', 72);
        Student stu4 = new Student("赵六", '女', 61);
        Student[] students = {stu1, stu2, stu3, stu4};

        StudentManagement stuM = new StudentManagement();
        StudentManage studentManage = stuM;
        studentManage.printInfo(students);
        studentManage.printAvgScore(students);

        StudentManage2 studentManage2 = stuM;
        studentManage2.printAvgScore2(students);
        studentManage2.printInfo2(students);

        StudentManage2.test01();
    }
}
